//
//  BLBasicTableViewController.m
//  新浪微博
//
//  Created by hbl on 16/3/9.
//  Copyright © 2016年 hbl. All rights reserved.
//

#import "BLBasicTableViewController.h"
@interface BLBasicTableViewController ()

@end

@implementation BLBasicTableViewController

- (NSMutableArray *)groups
{
    if (!_groups) {
        _groups = [NSMutableArray array];
    }
    return _groups;
}

- (instancetype)init
{
    if (self = [super init]) {
        self.tableView = [[UITableView alloc]initWithFrame:self.tableView.frame style:UITableViewStyleGrouped];
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.tableView.sectionFooterHeight = 5;
        self.tableView.sectionHeaderHeight = 0;
        self.tableView.contentInset = UIEdgeInsetsMake(-30, 0, 0, 0);
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return  self.groups.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    BLGroup *group = self.groups[section];
    return group.Items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BLSettingTableViewCell *cell = [BLSettingTableViewCell cellWithTableView:tableView];
    BLGroup *group = self.groups[indexPath.section];
    cell.item =group.Items[indexPath.row];
    cell.indexPath = indexPath;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    BLGroup *group = self.groups[indexPath.section];
    BLItem *item =group.Items[indexPath.row];
    if (item.option) {
        item.option();
    }
    if (item.theClass) {
        [self.navigationController pushViewController:[[item.theClass alloc]init] animated:YES];
    }
}



@end
